/* --------------------------------------------------------
 * Copyright (c) aeky , Inc.  All rights reserved.
 * --------------------------------------------------------
 */
package com.aeky.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 
 * @author aeky
 */
public class BaseMapData implements Serializable {

    private Byte _byte;
    private Short _short;
    private Integer _integer;
    private Long _long;
    private Float _float;
    private Double _double;
    private Date _date;
    private Boolean _boolean;

    private Byte[] _bytes;
    private Short[] _shorts;
    private Integer[] _integers;
    private Long[] _longs;
    private Float[] _floats;
    private Double[] _doubles;
    private Date[] _dates;
    private Boolean[] _booleans;

    private List<String> _list;
    private Set<String> _set;
    private Map<String, String> _map;

    private HashMap<String, Object> map = new HashMap<String, Object>();

    public BaseMapData() {

    }

    public BaseMapData(Map<String, Object> properties) {
        setProperties(properties);
    }

    public void setProperties(Map<String, Object> properties) {
        for (String property : properties.keySet()) {
            put(property, properties.get(property));
        }
    }

    public Map<String, Object> getProperties() {
        Map<String, Object> newMap = new HashMap<String, Object>();
        if (map != null) {
            newMap.putAll(map);
        }
        return newMap;
    }

    /**
     * Returns the internal map.
     * 
     * @return the map
     */
    public Map<String, Object> getTransientMap() {
        return map;
    }

    /**
     * Removes all the mappings from this map.
     */
    public void clear() {
        map.clear();
    }

    /**
     * Returns true if this map contains a mapping for this key.
     * 
     * @param key the key
     * @return true if mapping exists
     */
    public boolean containsKey(String key) {
        return map.containsKey(key);
    }

    /**
     * Returns true if this map maps one or more keys to the specified value.
     * 
     * @param value the value
     * @return true if this map maps one or more keys to the specified value
     */
    public boolean containsValue(Object value) {
        return map.containsValue(value);
    }

    /**
     * Returns a Set view of the mappings contained in this map.
     * 
     * @return a set view of the mappings
     */
    public Set<Map.Entry<String, Object>> entrySet() {
        return map.entrySet();
    }

    public boolean equals(Object o) {
        if (o instanceof BaseMapData) {
            return map.equals(((BaseMapData) o).map);
        }
        return false;
    }

    /**
     * Returns the value to which the specified key is mapped, or null if this
     * map contains no mapping for the key.
     * 
     * @param key the key
     * @return the value to which the specified key is mapped, or null if this
     *         map contains no mapping for the key
     */
    public Object get(String key) {
        return map.get(key);
    }

    public int hashCode() {
        return map.hashCode();
    }

    /**
     * Returns true if this map contains no key-value mappings.
     * 
     * @return true if this map contains no key-value mappings
     */
    public boolean isEmpty() {
        return map.isEmpty();
    }

    /**
     * Returns a Set view of the keys contained in this map.
     * 
     * @return a set view of the keys contained in this map
     */
    public Set<String> keySet() {
        return map.keySet();
    }

    /**
     * Associates the specified value with the specified key in this map
     * (optional operation).
     * 
     * @param key key with which the specified value is to be associated
     * @param value value to be associated with the specified key
     * @return the previous value associated with key, or null if there was no
     *         mapping for key
     */
    public Object put(String key, Object value) {
        return map.put(key, value);
    }

    /**
     * Copies all of the mappings from the specified map to this map (optional
     * operation).
     * 
     * @param m mappings to be stored in this map
     */
    public void putAll(Map<? extends String, ? extends Object> m) {
        map.putAll(m);
    }

    /**
     * Removes the mapping for a key from this map if it is present (optional
     * operation).
     * 
     * @param key key whose mapping is to be removed from the map
     * @return the previous value associated with key, or null if there was no
     *         mapping for key
     */
    public Object remove(Object key) {
        return map.remove(key);
    }

    /**
     * Returns the number of key-value mappings in this map.
     * 
     * @return the number of key-value mappings in this map
     */
    public int size() {
        return map.size();
    }

    /**
     * Returns a Collection view of the values contained in this map.
     * 
     * @return a collection view of the values contained in this map
     */
    public Collection<Object> values() {
        return map.values();
    }

    @Override
    public String toString() {
        return map.toString();
    }

}
